home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 October: Windmill on DISC / ADC Developer CD (1993-10) (''Windmill On DISC'')_iso / Dev.CD Oct 93.iso / Utilities / Installer v3.4.3 / Examples - Installer 3.4 / Installing Fonts / CheckTgtSysVer.c next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  4.1 KB  |  149 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  *
  3.  *    Apple Macintosh Developer Technical Support
  4.  *
  5.  *  Installer 3.4 sample: Action Atoms
  6.  *
  7.  *    File:        CheckTgtSysVer.c -    c Source
  8.  *
  9.  *    by:            Rich Kubota
  10.  *
  11.  *    Copyright © 1990-1992 Apple Computer, Inc.
  12.  *    All rights reserved.
  13.  *
  14.  *    Purpose: Sample to check that the target system is corresponds to the
  15.  *        required system version parameter passed in the aaRefCon field.
  16.  *        This code resource is used in conjunction with the installation
  17.  *        of Font Resources and the possibility that the user may select
  18.  *        a Font Installation designated for system 7.1, to be installed to
  19.  *        a target hard disk running System 7.0 or 7.0.1.  As noted in the 
  20.  *        script, Installer 3.4 will go ahead an create a Font folder
  21.  *        even though system 7.0 and 7.0.1 do not recognise this folder.
  22.  *        Conversely, you might also want to preflight that the user has
  23.  *        not selected a system 7.0 font installation for a system 7.1 target
  24.  *        volume
  25.  *
  26.  *        If the target system is does not match the desired system passed in the
  27.  *        aaRefCon field, the action atom displays an alert
  28.  *        and returns the result -1, otherwise, the code returns a result of noErr.
  29.  *        
  30.  *        This action atom is designed for use by Installer 3.3 and 3.4 only as it
  31.  *        returns a longint result instead of a Boolean
  32.  *
  33.  *----------------------------------------------------------------------------*/
  34.  
  35. #if 0
  36.  
  37. C -r -b  -mbg on CheckTgtSysVer.c
  38. Link -ra =resPurgeable -t rsrc -c RSED -rt infn=10000 ∂
  39.     -m CHECKTGTSYSVER -sg CheckTgtSysVer ∂
  40.     CheckTgtSysVer.c.o ∂
  41.     "{Libraries}"Interface.o ∂
  42.     -o CheckTgtSysVer.rsrc
  43.  
  44. #endif
  45.  
  46. #include <Types.h>
  47. #include <Quickdraw.h>
  48. #include <Memory.h>
  49. #include <Resources.h>
  50. #include <Files.h>
  51. #include <Dialogs.h>
  52. #include <ToolUtils.h>
  53. #include "ActionAtomIntf.h"
  54. #include "CheckTgtSysVer.h"
  55.  
  56.  
  57. /*    prototypes */
  58.     void AlertUser(short error );
  59.  
  60. #pragma segment CheckTgtSysVer
  61. pascal long    CHECKTGTSYSVER(AAPBRecPtr myAAPBPtr)
  62. {
  63.     Str32    sysName[] = "\pSystem";
  64.     short    sysRefNum;
  65.     short    saveResFile;
  66.     short    **versH;
  67.     Boolean    errFlag;
  68.     
  69.     // check that we have been called before the installation, return noErr if not
  70.     if (myAAPBPtr->whichStage != before) 
  71.         return (noErr);
  72.     
  73.     // Check that there is a blessed folder on the target volume
  74.     if (!myAAPBPtr->blessedDirID) {
  75.         AlertUser(kNoSystemAlert);
  76.         return ((long)-1);
  77.     }
  78.     
  79.     /*  Save the current resource file chain.  Even if the target system is on
  80.         the boot volume, the live system file is now in the temporary folder
  81.     */
  82.     
  83.     saveResFile = CurResFile();
  84.     
  85.     sysRefNum = HOpenResFile(myAAPBPtr->targetVRefNum, myAAPBPtr->blessedDirID,
  86.                     (ConstStr255Param) StripAddress((Ptr)sysName), fsRdPerm);
  87.     
  88.     if (sysRefNum == -1) {
  89.         // target system file not found
  90.         AlertUser(kNoSystemAlert);
  91.         return ((long)-1);
  92.     }
  93.     
  94.     // make sure that the tgt system file is at the head of the chain 
  95.     UseResFile(sysRefNum);
  96.     errFlag = false;        // assume no error has occured
  97.     
  98.     versH = (short**) Get1Resource(kversResourceType, kversResourceID);
  99.     if (!versH) {  
  100.         // we have memory problems if the 'vers' resource can't be loaded
  101.         AlertUser(kNoVerifyAlert);
  102.         errFlag = true;
  103.     }
  104.     else {
  105.         // now we get down to the task at hand
  106.         if (myAAPBPtr->aaRefCon == kSys71) {
  107.             // package for system 7.1 or greater selected
  108.             if (**versH < kSys71) {
  109.                 // target volume has system 7.0.1 or less        
  110.                 AlertUser(kSys71RequiredAlert);
  111.                 errFlag = true;
  112.             }
  113.         }
  114.         else {
  115.             // package for System 7.0.1 or earlier
  116.             if (**versH >= kSys71) {
  117.                 // target volume has system 7.1 or greater        
  118.                 AlertUser(kSys70RequiredAlert);
  119.                 errFlag = true;
  120.             }
  121.         }
  122.         // we're finished with the 'vers' resource
  123.         ReleaseResource((Handle)versH);
  124.     }
  125.     
  126.     CloseResFile(sysRefNum);      // finished with the target system file
  127.     
  128.     UseResFile(saveResFile);    // restore resource chain
  129.     
  130.     if (errFlag)
  131.         return (kBigBadErr);
  132.     else
  133.         return (noErr);
  134.     
  135. }
  136.  
  137. #pragma segment CheckTgtSysVer
  138. void AlertUser(error)
  139.     short        error;
  140. {
  141.     short        itemHit;
  142.     Str255        message;
  143.  
  144.     /* type Str255 is an array in MPW 3 */
  145.     GetIndString(message, kErrStrings, error);
  146.     ParamText(message, "", "", "");
  147.     itemHit = Alert(rUserAlert, nil);
  148. } /* AlertUser */
  149.